package com.westos.gui;

import com.westos.bean.RiskBean;

import javax.swing.*;
import java.awt.*;
import java.util.List;

public class Index2 extends JFrame {
    private List list;
    // 定义组件
    JPanel jp1;

    // 构造函数
    public Index2(List<RiskBean> list) {
        this.list = list;
        jp1 = new JPanel();
        JTextArea textArea = new JTextArea(40, 85);
        textArea.setLineWrap(true);//设置自动换行
        textArea.setWrapStyleWord(true);//设置以单词为整体
        textArea.setEditable(false);//设置无法编辑
        //将TextArea放入滚动条里面去
        JScrollPane scroll = new JScrollPane(textArea);
        //把定义的JTextArea放到JScrollPane里面去
        //分别设置水平和垂直滚动条自动出现
        scroll.setHorizontalScrollBarPolicy(
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scroll.setVerticalScrollBarPolicy(
                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

        int num = 0;
        for (RiskBean riskBean : list) {
            textArea.append(" 漏洞编号:" + ++num);
            textArea.append("\n");
            textArea.append(" 漏洞名称:" + riskBean.getRiskname().trim());
            textArea.append("\n");
            textArea.append(" 文件路径:" + riskBean.getFilepath().trim());
            textArea.append("\n");
            textArea.append(" 漏洞所在行号:" + riskBean.getRownum().toString());
            textArea.append("\n");
            textArea.append(" 漏洞代码:\n" + riskBean.getRiskcode().trim());
            textArea.append("\n\n");

        }

        //jb1 = new JButton("保存");
        //jb2 = new JButton("删除");

        this.setLayout(new GridLayout(1, 1));
        jp1.add(scroll);
        this.add(jp1);
        this.setSize(1000, 700);
        this.setTitle("代码审计");
        this.setVisible(true);

        //让窗口显示在屏幕中央
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screenSize =kit.getScreenSize();
        this.setBounds((screenSize.width-1000)/2, (screenSize.height-700)/2, 1000, 700);

    }


}
